﻿package  
{
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	import flash.events.TimerEvent;
	import flash.display.Sprite;
	import Box2D.Common.Math.b2Vec2;
	
	public class Bird extends Obstacle
	{
		private var birdChoice:Number;
		private var movement:Number = 0.22;
		private var deathAnim:String;
		//private var _animation:AnimatedSprite;
		public function Bird(X:Number, Y:Number,animation:AnimatedSprite) 
		{
			super(X, Y);
			var explode:Animation = new Animation(10);
			var idle:Animation = new Animation(22);
				
				
			idle.FramesPerSecond = 15;
			explode.FramesPerSecond = 20;
				
			
			this._animation = animation;
			
			
			
			this.birdChoice = Math.random() * 3;
			this.birdChoice = Math.ceil(birdChoice);
			
			if (birdChoice == 1)
			{
				this._animation.Animations["bird1"] = idle;
				this._animation.Animations["bird1_die"] = explode;
				this._animation.CurrentAnimation = "bird1";
				this.deathAnim = "bird1_die";
			}
			if (birdChoice == 2)
			{
				this._animation.Animations["bird2"] = idle;
				this._animation.Animations["bird2_die"] = explode;
				this._animation.CurrentAnimation = "bird2";
				this.deathAnim = "bird2_die";
			}
			if (birdChoice == 3)
			{
				this._animation.Animations["bird3"] = idle;
				this._animation.Animations["bird3_die"] = explode;
				this._animation.CurrentAnimation = "bird3";
				this.deathAnim = "bird3_die";
			}


			this._animation.StartAnimation();
			this.addChild(_animation);
		}
		public override function Update():Boolean
		{
			
			
			
			
			this.position.x -= movement;
			this.x = this.position.x * 30;
			
			//return true;
			return super.Update();
		}
		public override function Dispose():void
		{
			this.movement = 0;
			this._animation.CurrentAnimation = this.deathAnim;
			super.Dispose();
		
			
			//if(bHit)
				Main.sound.play("bird_hit");
		}
		
		
	}
	
}